﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AnimalCare.Model;
using AnimalCare.Service;

namespace AnimalCare.Controller
{
    /// <summary>
    ///
    /// </summary>
    class ClassificationService
    {
        /// <summary>
        /// Inserts the specified classification name.
        /// </summary>
        /// <param name="classificationName">Name of the classification.</param>
        public static void Insert(string classificationName)
        {
            Classification cf = new Classification();
            cf.classification_name = classificationName;
            using (var ctx = new AnimalCareDBEntities())
            {
                ctx.Classifications.AddObject(cf);
                ctx.SaveChanges();
            }
        }

        /// <summary>
        /// Updates the specified cf.
        /// </summary>
        /// <param name="cf">The cf.</param>
        public static void Update(Classification cf)
        {
            using (var ctx = new AnimalCareDBEntities())
            {
                var classification = (from s in ctx.Classifications
                                      where s.classification_id == cf.classification_id
                                      select s).FirstOrDefault();
                classification.classification_name = cf.classification_name;
                int num = ctx.SaveChanges();
            }
        }

        /// <summary>
        /// Deletes the specified identifier.
        /// </summary>
        /// <param name="id">The identifier.</param>
        public static void Delete(int id)
        {
            try
            {
                using (var ctx = new AnimalCareDBEntities())
                {
                    var cf = (from s in ctx.Classifications
                              where s.classification_id == id
                              select s).FirstOrDefault();
                    ctx.Classifications.DeleteObject(cf);
                    int num = ctx.SaveChanges();
                }
            }
            catch
            {
            }
        }
    }
}
